attribute vec3	inVertex;
attribute vec3	inNormal;

uniform mat4            mvpMatrix;
uniform mat4            mvMatrix;
uniform mediump vec3	lightDirection;

varying lowp    float	fDiffuse;
varying lowp    vec3    fFogIntensity;
varying mediump vec3    vertex;

void main(void)
{
	gl_Position = mvpMatrix * vec4(inVertex,1.0);
    
    // compute fog
    
	// transform position to view space as we need the distance to the eye for fog
	highp vec3 viewPos = vec3(mvMatrix * vec4(inVertex, 1.0));
	highp float eyeDist = length(viewPos);
    // Fog function is exponential squared.
    highp float scaledDist = eyeDist * 0.0025;
    //scaledDist *= scaledDist;
    highp float f = exp2(-scaledDist);
    // clamp the intensity within a valid range
	fFogIntensity = vec3(clamp(f, 0.0, 1.0));
    
    fDiffuse = max(dot(inNormal, normalize(lightDirection)), 0.0);
    
    vertex = inVertex;
}
